<template>
	<view class="page">
		<form @submit="login">
			<view class="input-block">
				<input type="text" 
				v-model="user.phone"
				class="input"
				placeholder="Py号/邮箱/手机号"
				@confirm="login"
				/>
				<input password="true" 
				v-model="user.password"
				class="input"
				placeholder="密码"
				@confirm="login"
				/>
			</view>
			
			<view >
				<button type="default" class="login-btn"
				style="background-color: #10D4FF;color: #ffffff;"
				form-type="submit"
				>登录</button>
			</view>
		
		</form>
		
		
		<view class="forgetAndRegister">
				<view class="forget">
					<text>忘记密码</text>
				</view>
				<view class="register" @click="toRegister">
					<text>用户注册</text>
				</view>
		</view>
		<!-- {{user.phone}}{{user.password}} -->
	</view>
</template>

<script>
	
	import utils from "@/common/util.js"
	import user from "@/api/user.js"
	var _self 
	
	export default {
		data() {
			return {
				user:{
					phone: '',
					password: ''
				}
			}
		},
		onNavigationBarButtonTap(e) {
			if(e.text == '取消'){
				uni.navigateBack({
					delta:1,
					// animationType: 'fade-out',
					// animationDuration: 200
				})
			}
		},
		onLoad(data){
			_self = this
			if(data.phone){
				this.user.phone = data.phone
			}
		},
		methods: {
			toRegister(){
				uni.navigateTo({
					url:'../register/register',
					animationType:'fade-in',
					animationDuration:300
				})
			},
			login(){
				if(this.user.phone == '' || this.user.password == ''){
					uni.showToast({
						title:'请填写完整！',
						icon:"none"
					})
				}else{
					user.login(this.user)
				}
			}
			
			
		}
	}
</script>

<style>
	@import url("addAndRegister.css");
</style>
